﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using System.IO;

namespace KaoQin.Common
{
    /// <summary>
    /// 记录日志
    /// </summary>
    public class Logger
    {
        [MethodImpl(MethodImplOptions.Synchronized)]
        public static void Write(object message)
        {
            string dir = Path.Combine(Application.StartupPath, "Log");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string fileName = Path.Combine(dir, "Log" + DateTime.Today.ToString("yyyyMMdd") + ".log");
            StreamWriter sw = new StreamWriter(fileName, true, Encoding.Unicode);
            try
            {
                sw.WriteLine("[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "]" + message.ToString());
            }
            finally
            {
                sw.Close();
            }
        }
    }
}
